<script>
	$(function(){
		Namespace.register("EBCMS.[namespace]");
		EBCMS.[namespace].queryParams = {
			page:1,
			rows:20,
			sort:'sort',
			order:'desc',
			__model:'recommend',
		};
		EBCMS.[namespace].refresh = function refresh(p){
			if (p) {
				$.each(p, function(index, val) {
					if (typeof val == 'object') {
						EBCMS.[namespace].queryParams[index] = $.extend(EBCMS.[namespace].queryParams[index], p[index]);
						delete p[index];
					};
				});
				$.extend(EBCMS.[namespace].queryParams, p);
			};
			EBCMS.CORE.api({
				queryParams:EBCMS.[namespace].queryParams,
				tpl:'[namespace]-table',
				target:'#[namespace]_main',
				compileAfter:function(p){
					$('#[namespace]_main').find('.input_sort').focus(function(){
						EBCMS.[namespace].sortvalue = $(this).val();
					}).blur(function(){
						var $this = $(this);
						if ($this.val() != EBCMS.[namespace].sortvalue) {
							EBCMS.ACT.togglefield('{:U('Recommend/resort')}',$this.data('id'),$this.val(),'[namespace]','resort');
						};
					});
					EBCMS.FN.renderPage('[namespace]',p.data.total);
				},
			});
		};
		EBCMS.[namespace].save = function save(id){
			EBCMS.CORE.get({
				url:'{:U('Recommend/save')}',
				queryParams:{
					id:id,
				},
				target:'#lgModal .modal-content',
				loadAfter:function(data,p){
					$('#lgModal').modal('toggle');
				},
			});
		};
		EBCMS.[namespace].add = function add(){
			if (EBCMS.[namespace].category_id) {
				EBCMS.CORE.get({
					url:'{:U('Recommend/add')}',
					queryParams:{
						category_id:EBCMS.[namespace].category_id,
					},
					target:'#lgModal .modal-content',
					loadAfter:function(data,p){
						$('#lgModal').modal('toggle');
					},
				});
			}else{
				EBCMS.MSG.tips('请先选择分类！');
			};
		};
		// EBCMS.[namespace].refresh();
	});
</script>

<div class="header">
	<div class="header-title" onclick="EBCMS.[namespace].refresh();">推荐管理</div>
	<div class="btn-group pull-right" role="group" aria-label="...">
		<a class="btn btn-success" href="javascript:EBCMS.[namespace].add()">添加</a>
	</div>
</div>
<div class="body" id="[namespace]_main">
</div>
<div class="footer">
	<div id="[namespace]_page" class="footer-page"></div>
</div>

<script id="[namespace]-table" type="text/html">
	{{each rows as v n}}
		<div class="media articlelist">
			<div class="media-left">
				<div style="width:100px;">
					<img src="{{v.thumb | realpath }}" alt="">
				</div>
			</div>
			<div class="media-body">
				<h4 class="media-heading">{{v.title}}</h4>
				<div class="helper">{{v.description}}</div>
			</div>
			<div class="media-right">
				<div style="width:48px;">
					<div class="btn-group-vertical btn-group-sm" role="group" aria-label="...">
						{{if access(0,'[namespace]','lock')}}
							{{if v.locked==1}}
							<a class="btn btn-default" href="javascript:EBCMS.ACT.lock('{:U('Recommend/lock')}','{{v.id}}','0','[namespace]');">已锁</a>
							{{else}}
							<a class="btn btn-default" href="javascript:EBCMS.ACT.lock('{:U('Recommend/lock')}','{{v.id}}','1','[namespace]');">未锁</a>
							{{/if}}
						{{/if}}
						{{if access(v.locked,'[namespace]','status')}}
							{{if v.status==1}}
							<a class="btn btn-default" href="javascript:EBCMS.ACT.status('{:U('Recommend/status')}','{{v.id}}','0','[namespace]');">已审</a>
							{{else}}
							<a class="btn btn-default" href="javascript:EBCMS.ACT.status('{:U('Recommend/status')}','{{v.id}}','1','[namespace]');">未审</a>
							{{/if}}
						{{/if}}
						{{if access(v.locked,'[namespace]','save')}}
						<a class="btn btn-default" href="javascript:EBCMS.[namespace].save('{{v.id}}');">编辑</a>
						{{/if}}
						{{if access(v.locked,'[namespace]','delete')}}
						<a class="btn btn-default" href="javascript:EBCMS.ACT.del('{:U('Recommend/delete')}','{{v.id}}','[namespace]');">删除</a>
						{{/if}}
					</div>
				</div>
			</div>
		</div>
	{{/each}}
</script>